package com.data.service.datasource;

import com.data.service.extension.DataSourceExtension;
import com.data.service.extension.Datasource;
import com.data.service.extension.DatasourceFactory;
import com.data.service.extension.DataSourceSwitcher;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class DatasourceServiceImpl implements DatasourceService {
    @Resource
    DatasourceFactory datasourceFactory;

    @Override
    public List<Map<String, Object>> query(String code, Map<String, String> params) {
        Datasource datasource = DataSourceSwitcher.getDataSource(code);

        DataSourceExtension dataSourceExtension = datasourceFactory.getDataSourceExtension(datasource.getType());

        return dataSourceExtension.execute(datasource, params);
    }
}
